{extend name="light-year/layout/master/detail" /}

{block name="title"}菜单管理{/block}
{block name="page-title"}菜单{/block}

{block name="content"}
    <input name="menu_id" class="form-control" type="hidden" value="{if $detail}{$detail->menu_id}{/if}" />
    <div class="form-group">
        <label><span class="text-danger">*</span> 父级栏目：</label>
        <div class="form-controls">
            <?php $parent_id = input('parent_id', 0);?>
            <select name="role_id" class="form-control" required>
                <option value="0">--默认顶级--</option>
                {if $menus}
                    {foreach $menus as $menu}
                        <option value="{$menu['menu_id']}"
                                {if $detail}
                                    {$menu['menu_id'] == $detail->parent_id ? 'selected' : ''}
                                {else /}
                                    {$menu['menu_id'] == $parent_id ? 'selected' : ''}
                                {/if}
                                > {$menu['menu_name']} </option>
                        {if !empty($menu['_child'])}
                            {foreach $menu['_child'] as $child}
                                <option value="{$child['menu_id']}"
                                        {if $detail}
                                            {$child['menu_id'] == $detail->parent_id ? 'selected' : ''}
                                        {else /}
                                            {$child['menu_id'] == $parent_id ? 'selected' : ''}
                                        {/if}
                                >├─{$child['menu_name']} </option>
                            {/foreach}
                        {/if}
                    {/foreach}
                {/if}
            </select>
        </div>
    </div>
    <div class="form-group">
        <label><span class="text-danger">*</span> 菜单名称：</label>
        <input type="text" class="form-control" name="menu_name" value="{if $detail}{$detail->menu_name}{/if}" placeholder="输入菜单名称" required="" />
        <small class="help-block">
            <i class="mdi mdi-information"></i>
            唯一标识
        </small>
    </div>
    <div class="form-group">
        <label>
            <span class="text-danger">*</span> 菜单模板类型：
        </label>
        <div class="clearfix">
            <?php $menu_type_list = cnpscy_config('menu_type_list') ?? [];?>
            {if !empty($menu_type_list)}
                {foreach $menu_type_list as $key => $val}
            <label class="lyear-radio radio-inline radio-primary display-block min-height-3-rem margin-left-3rem">
                <input type="radio" name="menu_tpltype" value="{$key}" {if (empty($detail) || $detail->menu_tpltype === $key) }checked{/if}><span>{$val}</span>
            </label>
                {/foreach}
            {/if}
        </div>
    </div>
    <div class="form-group">
        <label><span class="text-danger">*</span> 列表页：</label>
        <div class="form-controls">
            <select name="menu_list" class="form-control">
                <option value="">--请选择列表页--</option>
                {if $pages}
                    {foreach $pages as $page}
                    <option value="{$page}"
                            {if $detail}{$page == $detail->menu_list ? 'selected' : ''}{/if}
                        > {$page} </option>
                    {/foreach}
                {/if}
            </select>
        </div>
    </div>
    <div class="form-group">
        <label><span class="text-danger">*</span> 详情页：</label>
        <div class="form-controls">
            <select name="menu_detail" class="form-control">
                <option value="">--请选择详情页--</option>
                {if $pages}
                {foreach $pages as $page}
                <option value="{$page}"
                        {if $detail}{$page == $detail->menu_detail ? 'selected' : ''}{/if}
                    > {$page} </option>
                {/foreach}
                {/if}
            </select>
        </div>
    </div>
    <div class="form-group">
        <label> 页面路由：</label>
        <input type="text" class="form-control" name="menu_url" value="{if $detail}{$detail->menu_url}{/if}" placeholder="输入页面路由"/>
        <small class="help-block">
            <i class="mdi mdi-information"></i>
            访问页面路径（且仅支持一级，不支持多级），如果不填写，那么默认以菜单Id来区分！
        </small>
    </div>
    <div class="form-group">
        <label><span class="text-danger">*</span> 图标：</label>
        <input type="text" class="form-control" name="menu_icon" value="{if $detail}{$detail->menu_icon}{/if}" placeholder="输入图标"/>
        <small class="help-block">
            <i class="mdi mdi-information"></i>
            图标
        </small>
    </div>
    <div class="form-group">
        <label><span class="text-danger">*</span> 排序：</label>
        <input type="number" class="form-control" name="menu_sort" value="{if $detail}{$detail->menu_sort}{else/}1{/if}"/>
        <small class="help-block">
            <i class="mdi mdi-information"></i>
            从小到大，升序
        </small>
    </div>
    <div class="form-group">
        <label>
            是否展示：
        </label>
        <div class="clearfix">
            <label class="lyear-radio radio-inline radio-primary">
                <input type="radio" name="is_show" value="1" {if (empty($detail) || $detail->is_show === 1) }checked{/if}><span>启用</span>
            </label>
            <label class="lyear-radio radio-inline radio-primary">
                <input type="radio" name="is_show" value="0" {if (empty($detail) || $detail->is_show === 0) }checked{/if}><span>禁用</span>
            </label>
        </div>
    </div>
    <div class="form-group">
        <label> 单页内容内容：</label>
        <div id="test-editor" name="article_content">
            <textarea style="display:none;" name="menu_content">{if $detail}{$detail->menu_content}{/if}</textarea>
        </div>
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-primary ajax-post" target-form="add-form">确 定</button>
        <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);return false;">返 回</button>
    </div>
{/block}

{block name="script"}
{include file="light-year/layout:plugins/webuploader" /}
{include file="light-year/layout:plugins/editormd" /}

<script type="text/javascript">
    window.onload = function () {
        closeLayerLoading(closeAllLayer);

        // 图片上传组件
        webUploaderImgs('#article_cover_filePicker', '', '#article_cover', 'input[name=article_cover]', {'img_limit':1, 'single_graph_type':1});

        // 详情图片渲染（使用这种方式，可以共用图片上传限制等功能）
        let detail = JSON.parse('{:html_get_res_from_admin($detail)}');
        if (detail && !isEmpty(detail.article_cover)){
            $('#article_cover').append(webUploaderImgHtml(detail.article_cover, 'input[name=article_cover]', $('#article_cover_filePicker').attr('span-class')));
        }
    }
</script>
{/block}